package com.itheima.controller;

import com.itheima.domain.SmsHomeRecommendProduct;
import com.itheima.manager.SmsHomeRecommendProductManager;
import com.itheima.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class SmsHomeRecommendProductController {

    @Autowired
    SmsHomeRecommendProductManager smsHomeRecommendProductManager;

    /**
     * 营销-人气-分页条件查询
     * @param pageNum
     * @param pageSize
     * @param productName
     * @param recommendStatus
     * @return
     */
    @GetMapping("/home/recommendProduct/list")
    public R findByRecommendProductPage(Integer pageNum, Integer pageSize, String productName, Integer recommendStatus){
        return smsHomeRecommendProductManager.findByRecommendProductPage(pageNum,pageSize,productName,recommendStatus);
    }

    /**
     * 营销-人气-单个|多个修改推荐状态
     * @param ids
     * @param recommendStatus
     * @return
     */
    @PostMapping("/home/recommendProduct/update/recommendStatus")
    public R update(@RequestParam("ids") List<Long> ids, @RequestParam Integer recommendStatus){
        return smsHomeRecommendProductManager.update(ids,recommendStatus);
    }

    /**
     * 营销-人气-单个|多个删除
     * @param ids
     * @return
     */
    @PostMapping("/home/recommendProduct/delete")
    public R delete(@RequestParam("ids") List<Long> ids){
        return smsHomeRecommendProductManager.delete(ids);
    }

    /**
     * 营销-人气-修改排序
     * @param id
     * @param sort
     * @return
     */
    @PostMapping("/home/recommendProduct/update/sort/{id}")
    public R updateSort(@PathVariable Long id, @RequestParam Integer sort){
        return smsHomeRecommendProductManager.updateSort(id,sort);
    }

    /**
     * 营销-人气-添加首页新品
     * @param homeRecommendProductList
     * @return
     */
    @PostMapping("/home/recommendProduct/create")
    public R addProduct(@RequestBody List<SmsHomeRecommendProduct> homeRecommendProductList){
        return smsHomeRecommendProductManager.addProduct(homeRecommendProductList);
    }
}
